package com.googlecode.continuity.plugin.gwtext.client;

import com.google.gwt.user.client.ui.FocusListenerAdapter;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.Widget;

/**
 * Convenience class that offers a text area which contains a prompt in subdued colors.
 * The prompt disappears once the text area is focused.
 * <p/>
 * CSS Styles: .unSelected {} - applied as long as the box hasn't been focused yet.
 *
 * @author Peter Schmitt <aragos@aragos.de>
 */
public class PromptTextArea extends TextArea {
  private boolean showsPrompt;

  public PromptTextArea(String prompt) {
    showsPrompt = true;
    setText(prompt);
    addStyleName("unSelected");
    addFocusListener(new FocusListenerAdapter() {
      public void onFocus(Widget sender) {
        setText("");
        removeStyleName("unSelected");
        removeFocusListener(this);
        showsPrompt = false;
      }
    });
  }

  public boolean showsPrompt() {
    return showsPrompt;
  }
}
